﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;

namespace Project.module
{
    public partial class frmDichuyenban : Form
    {
        public BanDTO banmanager=null;
        public class ComboboxItem
        {
            public string Text { get; set; }
            public int Value { get; set; }

            public override string ToString()
            {
                return Text;
            }
        }
        public frmDichuyenban()
        {
            InitializeComponent();
        }

        private void frmDichuyenban_Load(object sender, EventArgs e)
        {
            banmanager = (BanDTO)this.Tag;
            List<KhuVucDTO> lstKV = KhuVucBUS.Listkhuvuc();
            if (lstKV.Count > 0)
            {
                foreach (KhuVucDTO kv in lstKV)
                {
                    ComboboxItem it=new ComboboxItem();
                    it.Text=kv.Tenkv;
                    it.Value=kv.Makv;
                    
                       
                    cbKhuvuc.Items.Add(it);
                }
                cbKhuvuc.SelectedText = KhuVucBUS.GetTenKV(banmanager.Makv) ;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int kv = (cbKhuvuc.SelectedItem as ComboboxItem).Value;
            bool kt = BanBUS.Update(banmanager.Maban, 0, kv, -1);
            if (kt == true)
            {
                MessageBox.Show("Cập nhật thành công !");
                this.Close();
            }
            else
            {
                MessageBox.Show("Lỗi cập nhật. Thử lại !");
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
